******************************************************************************************************
******************************************************************************************************
//-----------------------------DEMOCRACY AND MASS SKEPTICISM OF SCIENCE-----------------------------//
//-------------------------------------  WORLD POLITICS  -------------------------------------------//
//------------------------------ For Replication and Publication -----------------------------------//
******************************************************************************************************
******************************************************************************************************
//---------------NOTES---------------//
** Author: Junyan Jiang, Kin-Man Wan
** Last Updated: 
** Environment: 
*** Stata 17 SE
*** Windows 11 x64, AMD Ryzen 7 4800HS
*** 16GB RAM
**** Please create a folder "result_indiQ" UNDER "Replication" before you run the DO.file
**** Please create a folder "result_otherscience" UNDER "Replication" before you run the DO.file


//---------------WP REPLICATION DATA---------------//
use DATA_WP_jiang_wan_main, clear

//---------------MACROS---------------//
global cov ( i.female i.emp  i.urban_rural  i.income)
global agg ( c.loggdppc c.logpop c.log_nobel_pc c.log_qs500_pc   )

**************************************************************************
**************************************************************************
//----------------------------TABLES------------------------------------//
**************************************************************************
**************************************************************************

//---------------TABLE 1: Results from Cross-Sectional Analysis: Contemporary Level of Democracy---------------//
eststo clear
local var demo
reg y2    ///
c.`var'##i.edu , cluster(country ) 
local r2=e(r2_a)
eststo m1: expint y2 `var'
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary

local var demo
reghdfe y2       ///
c.`var'##i.edu  ,a(region i.birthyear) cluster(country ) 
local r2=e(r2_a)
eststo m2: expint y2 `var'
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary

local var demo
reghdfe y2    ///
c.`var'##i.edu $agg##i.edu $cov##c.`var'  ,a(region i.birthyear ) cluster(country ) 
local r2=e(r2_a)
eststo m3: expint y2 `var'
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary

local var e_polity2
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'   ,a(region i.birthyear ) cluster(country ) 
local r2=e(r2_a)
eststo m4: expint y2 `var' beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary

local var v2x_polyarchy
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'   ,a(region i.birthyear ) cluster(country ) 
local r2=e(r2_a)
eststo m5: expint y2 `var' beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary

local var fh_cont2
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'   ,a(region i.birthyear ) cluster(country ) 
local r2=e(r2_a)
eststo m6: expint y2 `var' beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary

esttab  m* using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01)refcat(primary "{\emph{Effect of democracy on ...}}" , nolabel) /// 
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Binary Polity" "Binary Polity"  "Binary Polity" "Continuous Polity" "Electoral democracy (V-Dem)" "Freedom House rating") ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe ctrl1 ctrl2 r2a  N, labels("Region and birth year FE" "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt(  0  0  0 2 0 ) )


//---------------TABLE 2: Results from Cross-Cohort Analysis: Lifetime Exposure to Democracy---------------//
eststo clear
local var dexp_demo6_14after
reghdfe y2     ///
c.`var'##i.edu     ,a(country) cluster(country)  keepsing
local r2=e(r2_a)
eststo m1: expint y2  `var'  beta
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

local var dexp_demo6_14after
reghdfe y2     ///
c.`var'##i.edu     ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m2: expint y2  `var'  beta
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

local var dexp_demo6_14after
 reghdfe y2     ///
c.`var'##i.edu    $agg##i.edu $cov##c.`var'   ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m3: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

local var dexp_polity_14after
 reghdfe y2     ///
c.`var'##i.edu   $agg##i.edu $cov##c.`var'  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m4: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

local var dexp_elecd_14after
reghdfe y2     ///
c.`var'##i.edu    $agg##i.edu $cov##c.`var'  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m5: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

local var dexp_fh_14after
reghdfe y2     ///
c.`var'##i.edu    $agg##i.edu $cov##c.`var' ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m6: expint y2  `var'   beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

esttab  m1 m2 m3 m4 m5 m6 using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\emph{Effect of cumulative exposure to democracy on ...}}" " " , nolabel) ///
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Binary democracy, age 14 to present" "Binary democracy, age 14 to present" "Binary democracy, age 14 to present" "Continuous democracy, age 14 to present" "Electoral democracy (V-Dem), age 14 to present" "Freedom House status, age 14 to present") ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe bfe ctrl1 ctrl2 r2a  N, labels("Country FE" "Birth year-education FE" "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt(  0  0  0 0 2 0 ) )


//---------------TABLE 3: Alternative Explanation: Democracy Is More Tolerant of Religion ---------------//
eststo clear
local var dexp_demo6_14after
eststo m1:  reghdfe y2     ///
`var'Xedu_nc      $cov##c.`var' $agg##i.edu_nc   if  reli_samp==1 ,a(country  i.birthyear##i.edu) cluster(country) keepsing
local b0=_b[`var'Xedu_nc]
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"

local var dexp_demo6_14after 
eststo m2: reghdfe y2     ///
`var'Xedu_nc      $cov##c.`var'  $agg##i.edu_nc  self_religion   if  reli_samp==1  ,a(country i.birthyear##i.edu) cluster(country) keepsing
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
estadd scalar change =(_b[`var'Xedu_nc]/`b0'-1)*100

local var dexp_demo6_14after 
eststo m3: reghdfe y2     ///
`var'Xedu_nc      $cov##c.`var' $agg##i.edu_nc   christians_pctXedu_nc   muslims_pctXedu_nc  if  reli_samp==1      ,a(country i.birthyear  i.birthyear##i.edu) cluster(country) keepsing
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
estadd scalar change =(1 - _b[`var'Xedu_nc]/`b0')*100

local var dexp_demo6_14after 
eststo m4: reghdfe y2     ///
`var'Xedu_nc      $cov##c.`var' $agg##i.edu_nc   v2clreligXedu_nc v2csrlgrepXedu_nc   if  reli_samp==1   ,a(country i.birthyear  i.birthyear##i.edu) cluster(country) keepsing
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
estadd scalar change =(1 - _b[`var'Xedu_nc]/`b0')*100

esttab m1 m2 m3 m4  using out.txt, nonote nobaselevels nogap keep( dexp_demo6_14afterXedu_nc self_religion  christians_pctXedu_nc muslims_pctXedu_nc    v2clreligXedu_nc v2csrlgrepXedu_nc ) b(3) se(3) order(dexp_demo6_14afterXedu_nc self_religion  christians_pctXedu_nc muslims_pctXedu_nc    v2clreligXedu_nc v2csrlgrepXedu_nc ) star(+ 0.1 * 0.05 ** 0.01) label booktabs replace  nomtitles ///
mgroup("Trust in Science (IRT)"  , pattern(1 0 0 0  ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  varlabel(dexp_demo6_14afterXedu_nc "Democratic exposure (after age 14) \(\times\) non-college \((\delta)\)") ///
stats( change   cfe cxe dxi  r2_a  N, labels("Mediation effect as \% of \(\delta\)"  "Country and birth year-education FE"  "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt( 2   0 0  0  2 0 ) )


//---------------TABLE 4: Mediation Effect of Political Trust ---------------//
* Binary Polity 
eststo clear
local var dexp_demo6_14after 
local mv trust_govt
eststo m1: reghdfe y2     ///
c.`var'Xedu_nc     $cov##c.`var'    $agg##i.edu_nc  if `mv'!=.     ,a(country   i.birthyear##i.edu) cluster(country)  keepsing

estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
local total = _b[`var'Xedu_nc]

reghdfe `mv'     ///
`var'Xedu_nc `var'   $cov##c.`var'   $agg##i.edu_nc  if `mv'!=.   ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local im = _b[`var'Xedu_nc]  // stored for computing mediation effect


local var dexp_demo6_14after
eststo m2: reghdfe y2     ///
`var'Xedu_nc  `mv'  $cov##c.`var'   $agg##i.edu_nc    if `mv'!=.   ,a(country   i.birthyear##i.edu) cluster(country) keepsing
local md = _b[`mv']
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
estadd scalar med_p = `md'*`im'/(`total')*100

* Continuous polity 
local var dexp_polity_14after 
local mv trust_govt
eststo m3: reghdfe y2     ///
c.`var'Xedu_nc     $cov##c.`var'     $agg##i.edu_nc if `mv'!=.    ,a(country   i.birthyear##i.edu) cluster(country)  keepsing

estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
local total = _b[`var'Xedu_nc]

reghdfe `mv'     ///
`var'Xedu_nc `var'   $cov##c.`var'      $agg##i.edu_nc  if `mv'!=.  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local im = _b[`var'Xedu_nc]  // stored for computing mediation effect


local var dexp_polity_14after
eststo m4: reghdfe y2     ///
`var'Xedu_nc  `mv'  $cov##c.`var'    $agg##i.edu_nc    if `mv'!=.  ,a(country   i.birthyear##i.edu) cluster(country) keepsing
local md = _b[`mv']
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
estadd scalar med_p = `md'*`im'/(`total')*100

* Electoral democracy 
local var dexp_elecd_14after 
local mv trust_govt
eststo m5: reghdfe y2     ///
`var'Xedu_nc     $cov##c.`var'    $agg##i.edu_nc   if `mv'!=.     ,a(country   i.birthyear##i.edu) cluster(country)  keepsing

estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
local total = _b[`var'Xedu_nc]

reghdfe `mv'     ///
`var'Xedu_nc    $cov##c.`var'    $agg##i.edu_nc    if `mv'!=.   ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local im = _b[`var'Xedu_nc]  // stored for computing mediation effect

local var dexp_elecd_14after
eststo m6: reghdfe y2     ///
`var'Xedu_nc  `mv'  $cov##c.`var'  $agg##i.edu_nc      if `mv'!=.   ,a(country   i.birthyear##i.edu) cluster(country) keepsing
local md = _b[`mv']
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
estadd scalar med_p = `md'*`im'/(`total')*100

esttab m*  using out.txt, nonote nobaselevels nogap keep(dexp_demo6_14afterXedu_nc dexp_polity_14afterXedu_nc dexp_elecd_14afterXedu_nc  trust_govt) b(3) se(3) ///
order(dexp_demo6_14afterXedu_nc dexp_polity_14afterXedu_nc dexp_elecd_14afterXedu_nc trust_govt) star(+ 0.1 * 0.05 ** 0.01) label booktabs replace nomtitles ///
mgroup("Trust in Science (IRT)"  , pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) varlabel(dexp_demo6_14afterXedu_nc "Democratic exposure (binary Polity) \(\times\) non-college" dexp_polity_14afterXedu_nc "Democratic exposure (continuous Polity) \(\times\) non-college") ///
stats( med_p   cfe cxe dxi  r2_a  N, labels("Mediation effect as \% of \(\delta\)"   "Country and birth year-education FE"  "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt( 2   0 0  0  2 0 ) )



//---------------TABLE 5: Analysis of Constitutional Texts and National Honors ---------------//
*See "DO_WP_jiang_wan_constitutions_honors"



**************************************************************************
**************************************************************************
**************************************************************************
//-----------------------APPENDIX: TABLES-------------------------------//
**************************************************************************
**************************************************************************

//---------------TABLE A.1: Summary Statistics for Survey Data---------------//
global sum y2 edu demo e_polity2 v2x_polyarchy fh_cont2  dexp_demo6_14after dexp_polity_14after  dexp_elecd_14after dexp_fh_14after gwf_personal gwf_party gwf_military  birthyear  religious  christians_pct muslims_pct v2clrelig  v2csrlgrep   trust_govt  female  emp  urban_rural  income loggdppc logpop log_nobel log_qs500  

eststo summ: estpost summarize  $sum 

esttab summ using out.txt, booktabs ///
nomtitle nonumber noobs cells("mean(fmt(a2)) sd(fmt(a2)) min max count") replace label


//---------------TABLE A.2: Summary Statistics for Constitutional Texts and State Honors ---------------//
*SEE "DO_WP_jiang_wan_constitutions_honors"


//---------------TABLE A.3: Comparison of Estimates for Different Education Levels: Cross-Sectional Models---------------//
eststo clear
local var demo
reg y2    ///
c.`var'##i.edu , cluster(country ) 
local r2=e(r2_a)
eststo m1: expint y2 `var'
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary


local var demo
reghdfe y2       ///
c.`var'##i.edu  ,a(region i.birthyear) cluster(country ) 
local r2=e(r2_a)
eststo m2: expint y2 `var'
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary

local var demo
reghdfe y2    ///
c.`var'##i.edu $agg##i.edu $cov##c.`var'  ,a(region i.birthyear ) cluster(country ) 
local r2=e(r2_a)
eststo m3: expint y2 `var'
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary

local var e_polity2
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'   ,a(region i.birthyear ) cluster(country ) 
local r2=e(r2_a)
eststo m4: expint y2 `var' beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary

local var v2x_polyarchy
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'   ,a(region i.birthyear ) cluster(country ) 
local r2=e(r2_a)
eststo m5: expint y2 `var' beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary

local var fh_cont2
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'   ,a(region i.birthyear ) cluster(country ) 
local r2=e(r2_a)
eststo m6: expint y2 `var' beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary


estimate restore m1
eststo mx1: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post
				
estimate restore m2
eststo mx2: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post

estimate restore m3
eststo mx3: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post

estimate restore m4
eststo mx4: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post

estimate restore m5
eststo mx5: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post
				
estimate restore m6
eststo mx6: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post				
				
esttab  mx* using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01)refcat(p_s "{\emph{Cross-sectional models}}" , nolabel) /// 
varlabel(p_s "Primary - Secondary" s_t "Secondary - College" p_t "Primary - College") ///
mtitles("Binary Polity" "Binary Polity"  "Binary Polity" "Continuous Polity" "Electoral democracy (V-Dem)" "Freedom House rating") ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))


//---------------TABLE A.4: Comparison of Estimates for Different Education Levels: Cross-Cohort Models---------------//
eststo clear
local var dexp_demo6_14after
reghdfe y2     ///
c.`var'##i.edu     ,a(country) cluster(country)  keepsing
local r2=e(r2_a)
eststo m1: expint y2  `var'  beta
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

local var dexp_demo6_14after
reghdfe y2     ///
c.`var'##i.edu     ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m2: expint y2  `var'  beta
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

local var dexp_demo6_14after
 reghdfe y2     ///
c.`var'##i.edu    $agg##i.edu $cov##c.`var'   ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m3: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

local var dexp_polity_14after
 reghdfe y2     ///
c.`var'##i.edu   $agg##i.edu $cov##c.`var'  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m4: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

local var dexp_elecd_14after
reghdfe y2     ///
c.`var'##i.edu    $agg##i.edu $cov##c.`var'  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m5: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

local var dexp_fh_14after
reghdfe y2     ///
c.`var'##i.edu    $agg##i.edu $cov##c.`var' ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m6: expint y2  `var'   beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
lincom primary-secondary
lincom primary-tertiary
lincom secondary-tertiary

estimate restore m1
eststo mx1: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post
				
estimate restore m2
eststo mx2: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post

estimate restore m3
eststo mx3: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post

estimate restore m4
eststo mx4: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post

estimate restore m5
eststo mx5: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post
				
estimate restore m6
eststo mx6: nlcom (p_s:(_b[primary]-_b[secondary])) ///
				(s_t:(_b[secondary]-_b[tertiary])) ///
				(p_t:(_b[primary]-_b[tertiary])), post				
				
esttab  mx* using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01)refcat(p_s "{\emph{Cross-cohort models}}" , nolabel) /// 
varlabel(p_s "Primary - Secondary" s_t "Secondary - College" p_t "Primary - College") ///
mtitles("Binary democracy, age 14 to present" "Binary democracy, age 14 to present" "Binary democracy, age 14 to present" "Continuous democracy, age 14 to present" "Electoral democracy (V-Dem), age 14 to present" "Freedom House status, age 14 to present") ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))


//---------------TABLE A.5: Robustness for Cross-Sectional Analysis: Using Alternative Measures of Democracy ---------------//
eststo clear
local var demo6_5
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'  ,a(region birthyear) cluster(country ) 
local r2=e(r2_a)
eststo m1: expint y2 `var' beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

local var polity2_5
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'  ,a(region birthyear) cluster(country ) 
local r2=e(r2_a)
eststo m2: expint y2 `var' beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'


local var elecd_5
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var' ,a(region birthyear) cluster(country ) 
local r2=e(r2_a)
eststo m3: expint y2 `var' beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

local var bmr
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var' ,a(region birthyear) cluster(country ) 
local r2=e(r2_a)
eststo m4: expint y2 `var'  
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

local var cgv_demo
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'  ,a(region birthyear) cluster(country ) 
local r2=e(r2_a)
eststo m5: expint y2 `var'  
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'


esttab  m* using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01)refcat(primary "{\emph{Effect of democracy on ...}}" , nolabel) /// 
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Binary Polity, 5-year average" "Continuous Polity, 5-year average"  "Electoral Polity (V-Dem), 5-year average" "Binary democracy (BMR)" "Binary democracy (CGV)" ) ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe ctrl1 ctrl2 r2a  N, labels("Region and birth year FE" "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt(  0  0  0 2 0 ) )


//---------------TABLE A.6: Cross-Cohort Analysis Using Alternative Democratic Exposure Measures ---------------//
eststo clear
local var dexp_demo6_11after
 reghdfe y2     ///
c.`var'##i.edu    $cov##c.`var' c.($agg)##i.edu    ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m1: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_demo6_6after
reghdfe y2     ///
c.`var'##i.edu    $cov##c.`var' c.($agg)##i.edu    ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m2: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_polity_11after
 reghdfe y2     ///
c.`var'##i.edu   $cov##c.`var' c.($agg)##i.edu    ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m3: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_polity_6after
 reghdfe y2     ///
c.`var'##i.edu   $cov##c.`var' c.($agg)##i.edu     ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m4: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_elecd_11after
reghdfe y2     ///
c.`var'##i.edu    $cov##c.`var' c.($agg)##i.edu     ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m5: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_elecd_6after
reghdfe y2     ///
c.`var'##i.edu    $cov##c.`var' c.($agg)##i.edu  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m6: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_fh_11after
reghdfe y2     ///
c.`var'##i.edu    $cov##c.`var' c.($agg)##i.edu     ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m7: expint y2  `var'   beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_fh_6after
reghdfe y2     ///
c.`var'##i.edu    $cov##c.`var' c.($agg)##i.edu     ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m8: expint y2  `var'   beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

esttab  m* using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\emph{Effect of cumulative exposure to democracy on ...}}" " " , nolabel) ///
varlabel(primary "Primary school or below" secondary "Secondary school" tertiary "College or above") ///
mtitles("Binary Polity, age 11 to present" "Binary Polity, age 6 to present" "Continuous Polity, age 11 to present" "Continuous Polity, age 6 to present" "Electoral democracy (V-Dem), age 11 to present" "Electoral democracy (V-Dem), age 6 to present" "Freedom House status, age 11 to present" "Freedom House status, age 6 to present") ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe bfe ctrl1 ctrl2 r2a  N, labels("Country FE" "Birth year-education FE" "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt(  0 0  0  0 2 0 ) )


//---------------TABLE A.7: Cross-Cohort Analysis Using Parsimonious Models---------------//
* Only birth and country fixed effect 
eststo clear
local var dexp_demo6_14after
reghdfe y2     ///
c.`var'##i.edu     ,a(country birthyear) cluster(country)  keepsing
local r2=e(r2_a)
eststo m1: expint y2  `var'  beta
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"

local var dexp_polity_14after 
reghdfe y2     ///
c.`var'##i.edu     ,a(country birthyear) cluster(country)  keepsing
local r2=e(r2_a)
eststo m2: expint y2  `var'  beta
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"

local var dexp_elecd_14after 
reghdfe y2     ///
c.`var'##i.edu     ,a(country birthyear) cluster(country)  keepsing
local r2=e(r2_a)
eststo m3: expint y2  `var'  beta 
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"

local var dexp_fh_14after 
reghdfe y2     ///
c.`var'##i.edu     ,a(country birthyear) cluster(country)  keepsing
local r2=e(r2_a)
eststo m4: expint y2  `var'  beta 
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"

esttab  m1 m2 m3 m4  using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\emph{Effect of cumulative exposure to democracy on ...}}" " " , nolabel) ///
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Binary democracy, age 14 to present" "Binary democracy, age 14 to present" "Binary democracy, age 14 to present" "Continuous democracy, age 14 to present" "Electoral democracy (V-Dem), age 14 to present" "Freedom House status, age 14 to present") ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe bfe   N, labels("Country FE" "Birth year FE"   "Observations") fmt(  0  0    0 ) )


//---------------TABLE A.8: Placebo Cross-Cohort Analysis ---------------//
eststo clear
eststo ma: reghdfe y2     ///
c.dexp_demo6_7to13##i.edu   c.dexp_demo6_0to6##i.edu c.dexp_demo6_0toN5##i.edu    $agg##i.edu   $cov , a(country i.birthyear##i.edu) cluster(country)  keepsing

eststo mb: reghdfe y2     ///
c.dexp_polity_7to13##i.edu   c.dexp_polity_0to6##i.edu c.dexp_polity_0toN5##i.edu   $agg##i.edu   $cov    ,a(country i.birthyear##i.edu) cluster(country)  keepsing

eststo mc: reghdfe y2     ///
c.dexp_elecd_7to13##i.edu   c.dexp_elecd_0to6##i.edu c.dexp_elecd_0toN5##i.edu   $agg##i.edu   $cov    ,a(country i.birthyear##i.edu) cluster(country)  keepsing

//// 7 to 13 /////
estimate restore ma
eststo m1: expint y2 dexp_demo6_7to13 beta
estadd local edugdp "$\checkmark$"
estadd local edupop "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"

estimate restore mb
eststo m2: expint y2 dexp_polity_7to13 beta
estadd local edugdp "$\checkmark$"
estadd local edupop "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"

estimate restore mc
eststo m3: expint y2 dexp_elecd_7to13 beta
estadd local edugdp "$\checkmark$"
estadd local edupop "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"

esttab  m1 m2 m3 using out.txt, b(3) se(3) nonote nobaselevel    noomitted   label  replace booktabs   star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\textbf{Placebo: democratic exposure for age 7 to 13}}"  " " , nolabel) ///
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Binary Polity" "Continuous Polity" "Electoral democracy (V-Dem)") mgroup("DV = Trust in Science (IRT)", pattern(1 0  0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe be  edugdp ctlX    N, labels("Country FE" "Birth year-education FE" "Country-level controls \(\times\) education"  "Individual-level controls"   "Observations") fmt(  0  0  0 0   0 ) )

//// 0 to 6 /////
estimate restore ma
eststo m1: expint y2 dexp_demo6_0to6 beta
estadd local edugdp "$\checkmark$"
estadd local edupop "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"

estimate restore mb
eststo m2: expint y2 dexp_polity_0to6 beta
estadd local edugdp "$\checkmark$"
estadd local edupop "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"

estimate restore mc
eststo m3: expint y2 dexp_elecd_0to6 beta
estadd local edugdp "$\checkmark$"
estadd local edupop "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"

esttab  m1 m2 m3 using out2.txt, b(3) se(3) nonote nobaselevel    noomitted   label  replace booktabs   star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\textbf{Placebo: democratic exposure for age 0 to 6}}"  " " , nolabel) ///
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Binary Polity" "Continuous Polity" "Electoral democracy (V-Dem)") mgroup("DV = Trust in Science (IRT)", pattern(1 0  0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe be  edugdp ctlX    N, labels("Country FE" "Birth year-education FE" "Country-level controls \(\times\) education"  "Individual-level controls"   "Observations") fmt(  0  0  0 0   0 ) )

//// -5 to 0  /////
estimate restore ma
eststo m1: expint y2 dexp_demo6_0toN5 beta
estadd local edugdp "$\checkmark$"
estadd local edupop "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"

estimate restore mb
eststo m2: expint y2 dexp_polity_0toN5 beta
estadd local edugdp "$\checkmark$"
estadd local edupop "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"

estimate restore mc
eststo m3: expint y2 dexp_elecd_0toN5 beta
estadd local edugdp "$\checkmark$"
estadd local edupop "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"

esttab  m1 m2 m3 using out3.txt, b(3) se(3) nonote nobaselevel    noomitted   label  replace booktabs   star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\textbf{Placebo: democratic exposure 5 yrs before birth}}" " " , nolabel) ///
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Binary Polity" "Continuous Polity" "Electoral democracy (V-Dem)") mgroup("DV = Trust in Science (IRT)", pattern(1 0  0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe be  edugdp ctlX    N, labels("Country FE" "Birth year-education FE" "Country-level controls \(\times\) education"  "Individual-level controls"   "Observations") fmt(  0  0  0 0   0 ) )


//---------------TABLE A.9: Controlling for Left-Right Ideology ---------------//
/*
label var ideology_cce "Self-placed ideology (proxied by country-cohort-education group average)"
label var demoXedu1 "Primary education or below"
label var demoXedu2 "Secondary education"
label var demoXedu3 "College education or above"
label var dexp_demo6_14afterXedu1 "Primary education or below"
label var dexp_demo6_14afterXedu2 "Secondary education"
label var dexp_demo6_14afterXedu3 "College education or above"
*/

// Cross-sectional
eststo clear
local var demo 
eststo m1: reghdfe y2    ///
demoXedu1 demoXedu2 demoXedu3   $agg##i.edu $cov##c.`var'   if ideology_cce!=.,a(region birthyear) cluster(country ) 
local r2=e(r2_a)
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

local var demo 
eststo m2: reghdfe y2    ///
demoXedu1 demoXedu2 demoXedu3   $agg##i.edu $cov##c.`var'  ideology_cce ,a(region birthyear) cluster(country ) 
local r2=e(r2_a)
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

// Cross cohort
local var dexp_demo6_14after
eststo m3: reghdfe y2     ///
dexp_demo6_14afterXedu1 dexp_demo6_14afterXedu2 dexp_demo6_14afterXedu3  $agg##i.edu $cov##c.`var'    if ideology_cce!=. ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local cfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_demo6_14after
eststo m4: reghdfe y2     ///
dexp_demo6_14afterXedu1 dexp_demo6_14afterXedu2 dexp_demo6_14afterXedu3  $agg##i.edu $cov##c.`var'    ideology_cce ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local cfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

esttab  m1 m2 m3 m4 using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01) keep(demoXedu1 demoXedu2 demoXedu3 ideology_cce) order(demoXedu1 demoXedu2 demoXedu3 ideology_cce) rename(dexp_demo6_14afterXedu1 demoXedu1 dexp_demo6_14afterXedu2 demoXedu2 dexp_demo6_14afterXedu3 demoXedu3) ///
refcat(demoXedu1 "{\emph{Effect of current/cumulative level of democracy on ...}}" " " , nolabel) ///
mtitles("Cross-sectional model" "Cross-cohort model") ///
mgroup("DV = Trust in Science (IRT)", pattern(1   ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe cfe bfe ctrl1 ctrl2 r2a  N, labels("Region and birth year FE" "Country FE" "Birth year-education FE" "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt( 0 0 0  0  0 2 0 ) )



//---------------TABLE A.10: Subsample Results ---------------//
/*
capture drop communist
g communist=country=="Vietnam"|country=="China"|country=="Russia"|country=="Belarus"|country=="Czech Republic" ///
|country=="Hungary"|country=="Poland"|country=="Slovakia"|country=="Mongolia"|country=="Albania"|country=="Ukraine"| ///
country=="Moldova"|country=="Estonia"|country=="Latvia"|country=="Lithuania"|country=="Kazakhstan"|country=="Kyrgyzstan"| ///
country=="Tajikistan"|country=="Turkmenistan"|country=="Uzbekistan"|country=="Armenia"|country=="Azerbaijan"|country=="Georgia" ///
|country=="Romania"|country=="Bosnia"|country=="Bulgaria"|country=="Croatia"|country=="Macedonia"|country=="Montenegro"| ///
country=="Serbia"|country=="Slovenia"|country=="Bosnia and Herzegovina"|country=="Montenegro"|country=="Laos"
*/

**************** Cross-sectional *********************
eststo clear
local var polity2_5 
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'  if developed==1 ,a(region birthyear) cluster(country )  keepsing
local r2=e(r2_a)
eststo m1: expint y2 `var' , beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

local var polity2_5 
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'  if developed==0 ,a(region birthyear) cluster(country )  keepsing
local r2=e(r2_a)
eststo m2: expint y2 `var'  , beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

local var polity2_5 
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'  if communist==0  ,a(region birthyear) cluster(country )  keepsing
local r2=e(r2_a)
eststo m3: expint y2 `var'  , beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

local var polity2_5 
reghdfe y2    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'  if populist_1718!=1  ,a(region birthyear) cluster(country )  keepsing
local r2=e(r2_a)
eststo m4: expint y2 `var'  , beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

esttab  m* using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\emph{Effect of democracy on ...}}" " " , nolabel) ///
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Western countries" "Non-Western countries" "Excluding former or current communist countries" "Exclude countries with populist leaders") ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe ctrl1 ctrl2 r2a  N, labels("Region and birth year FE" "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt(  0  0  0 2 0 ) )

**************** Cross-cohort *********************
eststo clear
local var dexp_polity_14after
reghdfe y2     ///
c.`var'##i.edu   $agg##i.edu $cov##c.`var' if developed==1 ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m1: expint y2  `var'    beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_polity_14after
reghdfe y2     ///
c.`var'##i.edu   $agg##i.edu $cov##c.`var' if developed==0 ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m2: expint y2  `var'    beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_polity_14after
reghdfe y2     ///
c.`var'##i.edu   $agg##i.edu $cov##c.`var' if communist==0  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m3: expint y2  `var'    beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_polity_14after
reghdfe y2     ///
c.`var'##i.edu   $agg##i.edu $cov##c.`var' if populist_1718!=1  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m4: expint y2  `var'    beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local ctlX "$\checkmark$"
estadd local be "$\checkmark$"
estadd local bc "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'

esttab  m* using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\emph{Effect of cumulative exposure to democracy on ...}}" " " , nolabel) ///
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College or above") ///
mtitles("Western countries" "Non-Western countries" "Excluding former or current communist countries" "Exclude countries with populist leaders") ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe  bc ctrl1  ctrl2   r2a  N, labels("Country FE" "Birth year-education FE" "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt(  0  0   0 0 2 0 ) )



//---------------TABLE A.11: Comparing between Countries with Low and High Return to Education ---------------//
/*
g return_edu = .
levelsof WP5, local(cid)
foreach i of local cid{
	capture reg hseincome edu if WP5==`i'
	capture replace return_edu = _b[edu] if  WP5==`i'  	
}

sum return_edu if tg==1 
* median value:   .6640414
*/

eststo clear
// low return countries//
local var dexp_demo6_14after
reghdfe y2     ///
c.dexp_demo6_14after##i.edu  $agg##i.edu $cov##c.`var'  if beta_income!=. & beta_income<  .6640414,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m1: expint y2  `var'   beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

// high return countries//
local var dexp_demo6_14after
reghdfe y2     ///
c.dexp_demo6_14after##i.edu  $agg##i.edu $cov##c.`var'  if beta_income!=. & beta_income>  .6640414,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m2: expint y2  `var'   beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
  
esttab  m1 m2   using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\emph{Effect of cumulative exposure to democracy on ...}}" " " , nolabel) ///
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Low return to education countries (bottom 50\%)" "High return to education countries (top 50\%)") ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0  ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe bfe ctrl1 ctrl2 r2a  N, labels("Country FE" "Birth year-education FE" "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt(  0  0  0 0 2 0 ) )


//---------------TABLE A.12: Addressing the Issue of Preference Falsification: Current Democracies Only ---------------//
eststo clear
local var dexp_demo6_14after
reghdfe y2     ///
c.`var'##i.edu     if demo==1 ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m1: expint y2  `var'  beta
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_demo6_14after
 reghdfe y2     ///
c.`var'##i.edu    $agg##i.edu $cov##c.`var'   if demo==1 ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m2: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_polity_14after
 reghdfe y2     ///
c.`var'##i.edu   $agg##i.edu $cov##c.`var' if demo==1  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m3: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

local var dexp_elecd_14after
reghdfe y2     ///
c.`var'##i.edu    $agg##i.edu $cov##c.`var' if demo==1  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m4: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

esttab  m1 m2 m3 m4   using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\emph{Effect of cumulative exposure to democracy on ...}}" " " , nolabel) ///
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Binary democracy, age 14 to present" "Binary democracy, age 14 to present" "Continuous democracy, age 14 to present" "Electoral democracy (V-Dem), age 14 to present" ) ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 0  ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe   ctrl1 ctrl2 r2a  N, labels("Country and birth year-education FE"  "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt(    0  0 0 2 0 ) )


//---------------TABLE A.13: Analysis of Science Attitudes from the WVS ---------------//
*See "DO_WP_jiang_wan_wvs"

//---------------TABLE A.14: Democracy and Post-Materialist Values ---------------//
*See "DO_WP_jiang_wan_wvs"


//---------------TABLE A.15: Cohort-Level Post-Materialist Values and Trust in Science ---------------//
* Post-Materialism: greater mass skepticism of science in country-cohorts with high materialist values 
eststo clear
local var wvsch_postmat
reghdfe y2     ///
c.`var'##i.edu     ,a(country) cluster(country)  keepsing
local r2=e(r2_a)
eststo m1: expint y2  `var'  beta
estadd local rfe "$\checkmark$"
estadd scalar r2a=`r2'


local var wvsch_postmat
reghdfe y2     ///
c.`var'##i.edu     ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m2: expint y2  `var'  beta
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'


local var wvsch_postmat
 reghdfe y2     ///
c.`var'##i.edu    $agg##i.edu $cov##c.`var'   ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m3: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'

// exclude populist leaders in power 2017--2018 //
local var wvsch_postmat
 reghdfe y2     ///
c.`var'##i.edu    $agg##i.edu $cov##c.`var'  if populist_1718!=1  ,a(country i.birthyear##i.edu) cluster(country)  keepsing
local r2=e(r2_a)
eststo m4: expint y2  `var'  beta
estadd local ctrl2 "$\checkmark$"
estadd local ctrl1 "$\checkmark$"
estadd local rfe "$\checkmark$"
estadd local bfe "$\checkmark$"
estadd scalar r2a=`r2'
 
esttab  m1 m2 m3 m4   using out.txt, b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace booktabs  star(+ 0.1 * 0.05 ** 0.01) ///
refcat(primary "{\emph{Effect of cohort-level post-materialism on ...}}" " " , nolabel) ///
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mtitles("Full sample" "Full sample" "Full sample" "Exclude populist leaders in power (2017-18)") ///
mgroup("DV = Trust in Science (IRT)", pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(rfe bfe ctrl1 ctrl2 r2a  N, labels("Country FE" "Birth year-education FE" "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt(  0  0  0 0 2 0 ) )


//---------------TABLE A.16: Using Interactions between Individual Religiosity and Aggregate Share of Religious Population as the Mediator---------------//
eststo clear
local var dexp_demo6_14after
eststo m1:  reghdfe y2     ///
`var'Xedu_nc      $cov##c.`var' $agg##i.edu_nc   if  reli_samp==1 ,a(country  i.birthyear##i.edu) cluster(country) keepsing
local b0=_b[`var'Xedu_nc]
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"

eststo m2: reghdfe y2     ///
`var'Xedu_nc      $cov##c.`var'  $agg##i.edu_nc  c.self_religion##c.(christians_pct muslims_pct buddhists_pct)  if  reli_samp==1  ,a(country i.birthyear##i.edu) cluster(country) keepsing
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
estadd scalar change =(_b[`var'Xedu_nc]/`b0'-1)*100

esttab m1 m2   using out.txt, nonote nobaselevels nogap keep( dexp_demo6_14afterXedu_nc *self_religion*   ) b(3) se(3) order(dexp_demo6_14afterXedu_nc self_religion  *self_religion* ) star(+ 0.1 * 0.05 ** 0.01) label booktabs replace  nomtitles ///
mgroup("Trust in Science (IRT)"  , pattern(1 0 0 0  ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  varlabel(dexp_demo6_14afterXedu_nc "Democratic exposure (after age 14) \(\times\) non-college \((\delta)\)") ///
stats( change   cfe cxe dxi  r2_a  N, labels("Mediation effect as \% of \(\delta\)"  "Country and birth year-education FE"  "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt( 2   0 0  0  2 0 ) )



//---------------TABLE A.17: Democracy and Student Performance in Science and Mathematics ---------------//
*See "DO_WP_jiang_wan_pisa_olympia"


//---------------TABLE A.18: Democracy and Performance in International Mathematical Olympiad ---------------//
*See "DO_WP_jiang_wan_pisa_olympia"



//---------------TABLE A.19: Mediation Analyses with Non-Political Trust---------------//
/*
label var trust_neighbor "Mediator: trust in neighbors"
label var trust_traditionhealers "Mediator: trust in traditional healers"
*/

eststo clear
/// Neighbor ///
local var dexp_elecd_14after 
local mv trust_neighbor
eststo m1: reghdfe y2     ///
c.`var'Xedu_nc     $cov##c.`var'    $agg##i.edu_nc if `mv'!=.    ,a(country   i.birthyear##i.edu) cluster(country)  keepsing

estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
local total = _b[`var'Xedu_nc]

reghdfe `mv'     ///
`var'Xedu_nc `var'   $cov##c.`var'    $agg##i.edu_nc  if `mv'!=.  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local im = _b[`var'Xedu_nc]  // stored for computing mediation effect


eststo m2: reghdfe y2     ///
`var'Xedu_nc  `mv'  $cov##c.`var'  $agg##i.edu_nc    if `mv'!=.  ,a(country   i.birthyear##i.edu) cluster(country) keepsing
local md = _b[`mv']
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
estadd scalar med_p = `md'*`im'/(`total')*100

/// Healers ///
local var dexp_elecd_14after 
local mv trust_traditionhealers
eststo m3: reghdfe y2     ///
c.`var'Xedu_nc     $cov##c.`var'    $agg##i.edu_nc if `mv'!=.    ,a(country   i.birthyear##i.edu) cluster(country)  keepsing

estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
local total = _b[`var'Xedu_nc]

reghdfe `mv'     ///
`var'Xedu_nc `var'   $cov##c.`var'    $agg##i.edu_nc  if `mv'!=.  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
local im = _b[`var'Xedu_nc]  // stored for computing mediation effect

eststo m4: reghdfe y2     ///
`var'Xedu_nc  `mv'  $cov##c.`var'  $agg##i.edu_nc    if `mv'!=.  ,a(country   i.birthyear##i.edu) cluster(country) keepsing
local md = _b[`mv']
estadd local cfe "$\checkmark$"
estadd local cxe "$\checkmark$"
estadd local dxi "$\checkmark$"
estadd scalar med_p = `md'*`im'/(`total')*100

esttab m*  using out.txt, nonote nobaselevels nogap keep(dexp_elecd_14afterXedu_nc    trust_neighbor   trust_traditionhealers) b(3) se(3) ///
order(dexp_elecd_14after*     trust_neighbor   trust_traditionhealers) star(+ 0.1 * 0.05 ** 0.01) label booktabs replace nomtitles ///
mgroup("Trust in Science (IRT)"  , pattern(1 0 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) varlabel(dexp_demo6_14afterXedu_nc "Democratic exposure (binary Polity) \(\times\) non-college" dexp_polity_14afterXedu_nc "Democratic exposure (continuous Polity) \(\times\) non-college") ///
stats( med_p  cfe cxe dxi  r2_a  N, labels("Mediation effect as \% of \(\delta\)"   "Country and birth year-education FE"  "Country-level controls \(\times\) education"  "Democracy \(\times\) indiv. controls" "Adjusted R$^2$"  "Observations") fmt( 2   0 0  0  2 0 ) )






//---------------TABLE A.21: Science Honors and Trust in Science among the Less Educated---------------//
*See "DO_WP_jiang_wan_constitutions_honors"




************************************************************************************************
************************************************************************************************
***************************** NUMERICAL DATA/RESULTS FOR FIGURES  ******************************
************************************************************************************************
************************************************************************************************
//---------------FIGURE 1: Average Trust in Science by Country/Region and Education Level---------------//
preserve
collapse (mean) oecd y_ledu y_medu y_hedu y_lmedu e_polity2 female demo edu  age loggdppc urban_rural hseincome log_nobel_pc log_qs500_pc  ///
(first) iso3 region,  by(country)

save "[F]DATA_country_level", replace
restore

//---------------FIGURE 2: Unpacking Non-democratic Regime Types---------------//
//// Cross Section ////
local var (demo gwf_monarchy gwf_personal gwf_party gwf_military)
eststo mr: reghdfe y2    ///
c.`var'##i.edu $agg##i.edu $cov##c.`var'  ,a(region birthyear) cluster(country ) 

eststo m1: nlcom (d_primary:(_b[demo]-_b[gwf_personal])) /// personal
	(d_secondary:(_b[demo] - _b[gwf_personal] + _b[2.edu#c.demo] - _b[2.edu#c.gwf_personal] )) ///
	(d_tertiary:(_b[demo] - _b[gwf_personal] + _b[3.edu#c.demo] - _b[3.edu#c.gwf_personal] )) ///
	(d_primary:(_b[demo] - _b[gwf_party])) /// party
	(d_secondary:(_b[demo]  - _b[gwf_party] + _b[2.edu#c.demo]  - _b[2.edu#c.gwf_party])) ///
	(d_tertiary:(_b[demo] - _b[gwf_party] + _b[3.edu#c.demo] - _b[3.edu#c.gwf_party] )) ///
	(d_primary:(_b[demo] - _b[gwf_military])) /// military
	(d_secondary:(_b[demo] - _b[gwf_military] + _b[2.edu#c.demo] - _b[2.edu#c.gwf_military])) ///
	(d_tertiary:(_b[demo] - _b[gwf_military] + _b[3.edu#c.demo] - _b[3.edu#c.gwf_military])) ///
	(d_primary:(_b[demo] - _b[gwf_monarchy])) /// monarchy
	(d_secondary:(_b[demo] - _b[gwf_monarchy] + _b[2.edu#c.demo] - _b[2.edu#c.gwf_monarchy])) ///
	(d_tertiary:(_b[demo] - _b[gwf_monarchy] + _b[3.edu#c.demo] - _b[3.edu#c.gwf_monarchy])), post

matrix B=r(b)
matrix D = r(V)

putexcel set "beta_cs.xlsx", sheet("D") replace
putexcel A1=matrix(B)

putexcel set "cov_cs.xlsx", sheet("D") replace
putexcel A1=matrix(D)


//// Cross Cohort ////
local var ( dexp_demo6_14after  dexp_gwfmonarchy_14after  dexp_gwfpersonal_14after dexp_gwfparty_14after dexp_gwfmilitary_14after)
eststo mr2: reghdfe y2     ///
c.`var'##i.edu   $agg##i.edu $cov##c.`var'  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing

eststo m1: nlcom (d_primary:(_b[dexp_demo6_14after] - _b[dexp_gwfpersonal_14after])) /// personal
	(d_secondary:(_b[dexp_demo6_14after] - _b[dexp_gwfpersonal_14after]  + _b[2.edu#c.dexp_demo6_14after] - _b[2.edu#c.dexp_gwfpersonal_14after]   )) ///
	(d_tertiary:(_b[dexp_demo6_14after] - _b[dexp_gwfpersonal_14after] + _b[3.edu#c.dexp_demo6_14after] - _b[3.edu#c.dexp_gwfpersonal_14after])) ///
	(d_primary:(_b[dexp_demo6_14after] - _b[dexp_gwfparty_14after])) /// party
	(d_secondary:(_b[dexp_demo6_14after] - _b[dexp_gwfparty_14after]  + _b[2.edu#c.dexp_demo6_14after] - _b[2.edu#c.dexp_gwfparty_14after] )) ///
	(d_tertiary:(_b[dexp_demo6_14after]  - _b[dexp_gwfparty_14after]+ _b[3.edu#c.dexp_demo6_14after] - _b[3.edu#c.dexp_gwfparty_14after] )) ///
	(d_primary:(_b[dexp_demo6_14after] - _b[dexp_gwfmilitary_14after])) /// military
	(d_secondary:(_b[dexp_demo6_14after] - _b[dexp_gwfmilitary_14after] + _b[2.edu#c.dexp_demo6_14after] -  _b[2.edu#c.dexp_gwfmilitary_14after])) ///
	(d_tertiary:(_b[dexp_demo6_14after] - _b[dexp_gwfmilitary_14after] + _b[3.edu#c.dexp_demo6_14after] - _b[3.edu#c.dexp_gwfmilitary_14after])) ///
	(d_primary:(_b[dexp_demo6_14after] - _b[dexp_gwfmonarchy_14after])) /// monarchy
	(d_secondary:(_b[dexp_demo6_14after] - _b[dexp_gwfmonarchy_14after]  + _b[2.edu#c.dexp_demo6_14after]- _b[2.edu#c.dexp_gwfmonarchy_14after])) ///
	(d_tertiary:(_b[dexp_demo6_14after] - _b[dexp_gwfmonarchy_14after] + _b[3.edu#c.dexp_demo6_14after] - _b[3.edu#c.dexp_gwfmonarchy_14after])), post

matrix B=r(b)
matrix D = r(V)

putexcel set "beta.xlsx", sheet("D") replace
putexcel A1=matrix(B)

putexcel set "cov.xlsx", sheet("D") replace
putexcel A1=matrix(D)



//---------------FIGURE A.1: Distribution of Science-Related Questions in the WGM---------------//
preserve
keep trust_science trust_scientist trust_scientistinfo trust_doctors ///
scientistuni_benifitpublic scientistuni_workfor scientistcomp_benifitpublic scientistcomp_workfor ///
scientist_benifitfor scientist_benifityou tech_benifitfor tech_increasejob religious_vs_science edu
save "[F]DATA_distribution", replace
restore

//---------------FIGURE A.2: Validation of Science Attitudes: WGM vs. WVS---------------//
preserve
collapse (mean) y2 religious_vs_science,by(iso3 edu)
save "[F]DATA_wgm_y2_byedu.dta", replace
restore

//---------------FIGURE A.3: Validation of Science Attitudes: WGM vs. Pew---------------//
preserve
collapse (mean) y2 religious_vs_science trust_scientist,by(iso3)
save "[F]DATA_wgm_y2.dta", replace
restore

//---------------FIGURE A.4: Principal Component Analysis (PCA) on Science Attitude Questions---------------//
*USE "DATA_WP_jiang_wan_main"


//---------------FIGURE A.5: Full Visualization of Average Trust in Science by the Least Educated Group (Primary or Below)---------------//
*SAME AS "FIGURE 1"
*USE "data_country_level_20220725"


//---------------FIGURE A.6: Full Visualization of Average Trust in Science by the Highly Educated Group (College or Above)---------------//
*SAME AS "FIGURE 1"
*USE "data_country_level_20220725"


//---------------FIGURE A.7: Cohort-based Variation in Democratic Exposure: An Illustration---------------//
preserve
collapse (first) dexp_demo6_14after,by(country birthyear)
save "[F]DATA_cohort_exposure.dta", replace
restore	


//---------------FIGURE A.8: Estimation Results for Individual Questions---------------//
local v trust_scientist trust_doctors trust_science trust_scientistinfo ///
	scientistuni_benifitpublic scientistuni_workfor scientistcomp_benifitpublic ///
	scientistcomp_workfor scientist_benifitfor scientist_benifityou tech_benifitfor ///
	tech_increasejob religious_vs_science
	
foreach i of local v{
local var e_polity2
reghdfe `i'    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'   ,a(region birthyear) cluster(country ) 
expint `i' `var' beta
expmat ".\result_indiQ\cs_`i'"

local var dexp_polity_14after
 reghdfe `i'     ///
c.`var'##i.edu   $agg##i.edu $cov##c.`var'  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
expint `i'  `var'  beta
expmat ".\result_indiQ\ch_`i'"
}




//---------------FIGURE A.9: Estimation Results for Questions Related to Scientific Knowledge---------------//
local v sci_know sci_understand sci_diseases sci_poetry  info_sci knowmore_sci  

foreach i of local v{
local var e_polity2
reghdfe `i'    ///
c.`var'##i.edu  $agg##i.edu $cov##c.`var'   ,a(region birthyear) cluster(country ) 
expint `i' `var' beta
expmat ".\result_otherscience\cs_`i'"

local var dexp_polity_14after
reghdfe `i'     ///
c.`var'##i.edu   $agg##i.edu $cov##c.`var'  ,a(country  i.birthyear##i.edu) cluster(country)  keepsing
expint `i'  `var'  beta
expmat ".\result_otherscience\ch_`i'"

}



//---------------------------------------------------------------THE END-----------------------------------------------------------------------//
